package com.kaiupup.study.controller;

import com.kaiupup.study.dto.ResponseResult;
import com.kaiupup.study.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @projectName: kaiupup-online-taxi
 * @package: com.kaiupup.study.controller
 * @className: NumberCodeControoller
 * @author: kaiupup
 * @description: TODO
 * @date: 2024/1/19 18:28
 * @version: 1.0
 */

@RestController
public class NumberCodeControoller {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size) {

        System.out.println("size = " + size);
        //生成验证码
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
        System.out.println("mathRandom = " + mathRandom);
        int resultInt = (int) mathRandom;

        NumberCodeResponse numberCodeResponse = new NumberCodeResponse();
        numberCodeResponse.setNumberCode(resultInt);


        return ResponseResult.success(numberCodeResponse);
    }

}
